package cn.wky.cale.key.board;

import android.app.Activity;
import android.view.View;

import cn.wky.cale.R;

public class NumKeyBoard implements View.OnClickListener {

    public NumKeyBoard(Activity activity) {
        activity.findViewById(R.id.num0).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num1).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num2).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num3).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num4).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num5).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num6).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num7).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num8).setOnClickListener(this::onClick);
        activity.findViewById(R.id.num9).setOnClickListener(this::onClick);
        activity.findViewById(R.id.dot).setOnClickListener(this::onClick);
        activity.findViewById(R.id.del).setOnClickListener(this::onClick);
        activity.findViewById(R.id.add).setOnClickListener(this::onClick);
        activity.findViewById(R.id.sub).setOnClickListener(this::onClick);
        activity.findViewById(R.id.mul).setOnClickListener(this::onClick);
        activity.findViewById(R.id.div).setOnClickListener(this::onClick);
    }

    private void updateStatus() {

    }

    public static interface KeyBoardDown {
        /**
         * 0-9:数字
         * 10:小数点
         * 11-14:加减乘除
         * -1:删除
         *
         * @param keyCode
         */
        void onDown(int keyCode);
    }

    KeyBoardDown down;

    public void setDown(KeyBoardDown down) {
        this.down = down;
    }

    @Override
    public void onClick(View v) {
        if (down == null) return;
        switch (v.getId()) {
            case R.id.num0:
                down.onDown(0);
                break;
            case R.id.num1:
                down.onDown(1);
                break;
            case R.id.num2:
                down.onDown(2);
                break;
            case R.id.num3:
                down.onDown(3);
                break;
            case R.id.num4:
                down.onDown(4);
                break;
            case R.id.num5:
                down.onDown(5);
                break;
            case R.id.num6:
                down.onDown(6);
                break;
            case R.id.num7:
                down.onDown(7);
                break;
            case R.id.num8:
                down.onDown(8);
                break;
            case R.id.num9:
                down.onDown(9);
                break;
            case R.id.dot:
                down.onDown(10);
                break;
            case R.id.add:
                down.onDown(11);
                break;
            case R.id.sub:
                down.onDown(12);
                break;
            case R.id.mul:
                down.onDown(13);
                break;
            case R.id.div:
                down.onDown(14);
                break;
            case R.id.del:
                down.onDown(-1);
                break;
        }
    }
}
